#include "StdAfx.h"

#include "FirstIntersectionResult.h"
#include "SecondIntersectionResult.h"
#include "Intersectable.h"
#include "Plain.h"

#include "FlatDisc.h"

FlatDisc::FlatDisc(const Ray& ray, double radius, const Color& color) : _plain(ray, Color(0, 0, 0)), _color(color) , _center(ray.P), _radiusSquared(radius * radius) 
{}

void FlatDisc::WhereIntersects(const Ray& ray, FirstIntersectionResult& result)
{
	_plain.WhereIntersects(ray, result);

	Point V = ray.D * result.Distance + ray.P - _center;

	if (V.ScalarProduct(V) > _radiusSquared)
		result.Set(this);
	else
		result.Set(result.Distance, this);
}

void FlatDisc::ColorAtIntersection(SecondIntersectionResult& result, const Point&, const Ray&)
{
	result.ColorAtPoint = _color;
}

Direction FlatDisc::NormalAtPoint(FirstIntersectionResult& result, const Point&)
{
	return _plain.NormalAtPoint(result, Point(0, 0, 0));
}

FlatDisc::~FlatDisc()
{}
